# If you plan on adding other embeddings, import them here
# from some_other_module import AnotherEmbeddingClass
from app.core import config
from app.core.config import settings
from app.llama_index.embeddings.openai_embedding import OpenAIEmbedding


class EmbeddingsFactory:
    @staticmethod
    def create(_embeddings_provider:str=None):
        """
        Factory method to create an embeddings instance based on .env config.
        """
        # Suppose your .env has a value like EMBEDDINGS_PROVIDER=openai
        if _embeddings_provider is None:
            _embeddings_provider = settings.EMBEDDINGS_PROVIDER.lower()

        if _embeddings_provider == "openai":
            return OpenAIEmbedding(
                api_key=settings.OPENAI_API_KEY,
                api_base=settings.OPENAI_API_BASE,
                model=settings.OPENAI_EMBEDDINGS_MODEL,
                # 指定向量维度（仅 text-embedding-v3 支持该参数）
                dimensions=None if settings.OPENAI_EMBEDDINGS_DIMENSIONS == 0 else settings.OPENAI_EMBEDDINGS_DIMENSIONS,
            )
        else:
            raise ValueError(f"不支持的嵌入模型提供者: {_embeddings_provider}")
